#!/usr/local/bin/python
# -*- coding: utf-8 -*-
# Copyright (c) The PyAMF Project.
# 影片列表 影片报告
# See LICENSE.txt for details.

import kernel.base.data as user_data
import kernel.base.function as func

class login:
    classname=None
    
    def __init__(self):
        self.classname="login"
        
    def user_reg(self,user_id,user_name,pwd,nickname,sex,email,pic):
        """*
         * 报告影片特征码
         * @param integer user_id 用户ID
         * @param integer user_name 用户名
         * @param integer pwd 密码
         * @param integer nickname 昵称
         * @param list sex 性别 1男 2女
         * @param list email 邮箱
         * @param list pic 头像
         * @return arr
        """
        fp=user_data.get_user(user_id)
        if(fp==False):
            return False
        
        mdata=user_data.storage().findone("user_info",{"user_name":user_name})
        if(mdata):
            return False
        
        addlist={
                 "id":user_data.storage().max_id("user_info"),
                 "e":1,
                 "online":0,
                 "time":func.systime(),
                 "user_name":user_name,
                 "pwd":pwd,
                 "nickname":nickname,
                 "sex":sex,
                 "email":email,
                 "pic":pic,
                }
        
        user_data.storage().add("user_info",addlist)
        return True
        
    def login(self,user_id,user_name,pwd):
        """*
         * 登录
         * @param integer user_id 用户ID
         * @param string user_name 用户名
         * @param string pwd 密码
         * @return arr
        """
        mdata=user_data.storage().findone("user_info",{"user_name":user_name,"pwd":pwd},{"id":1})
        if(mdata):
            return False
        
        fp=user_data.get_user(user_id)
        if(fp==False):
            return False
        
        user_data.move_user(user_id, mdata["id"])
        user_data.storage().findone("user_info",{"online":1},{"user_name":user_name})
        return True
    
    